<script setup lang="ts">
import EduMenu from './EduMenu.vue';
import EduTab from './EduTab.vue';
import { useDashboardStore, useAuthStore } from '@/store';
import { ElMessage } from 'element-plus';

import { onMounted, watch } from 'vue';
import { useRouter } from 'vue-router';

const authStore = useAuthStore();
const router = useRouter();
const dashboardStore = useDashboardStore();
onMounted(async () => {
    try {
        await dashboardStore.getMenu();
    } catch (e) { console.log(e) }
});
const goOut = () => {
    //清空缓存
    sessionStorage.clear();
    ElMessage({
        type: "success",
        showClose: true,
        message: ('退出登录'),
        customClass: "messageIndex"
    });
    router.push('/login');
};
watch(() => dashboardStore.activeFuncKey, (newFuncKey: string) => {
    router.replace("/home/" + newFuncKey);
}, { flush: "post" });
</script>

<template>
    <el-container id="particles">
        <el-header>
            <div class="header-l">
                <img src="../assets/images/sn.png" alt="">
                <h1>山农教务管理系统-V2.0</h1>
                <el-button type="primary" plain @click="dashboardStore.collapse = !dashboardStore.collapse"
                    color="#b85d71">
                    <el-icon>
                        <Expand v-if="dashboardStore.collapse" />
                        <Fold v-else />
                    </el-icon>
                </el-button>
            </div>
            <div class="header-r">
                <img class="header-r-img" src="../assets/images/tx.jpg" />
                <span v-text="authStore.userName"></span>
                <el-button type="primary" @click="goOut">退出登录</el-button>
            </div>

        </el-header>
        <el-container>
            <el-aside :width="dashboardStore.collapse ? '70px' : '300px'">
                <el-menu :collapse="dashboardStore.collapse" text-color="#fff" background-color=tranparent
                    active-text-color="#ffd04b" :default-active="dashboardStore.activeFuncKey"
                    @select="dashboardStore.openFunc">
                    <EduMenu :list="dashboardStore.menuTree" />
                </el-menu>
            </el-aside>
            <el-container>
                <el-main>
                    <EduTab />
                </el-main>
                <el-footer height="30px">
                    <p class="foot">&copy; 版权所有：山东农业大学 2022 </p>
                </el-footer>
            </el-container>
        </el-container>
    </el-container>
</template>

<style scoped>
.el-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 90px;
    background-image: url(../assets/images/bgc22.webp);
    background-size: cover;
    background-position: 0 7%
}

.header-l {
    display: flex;
    align-items: center;
}

img {
    width: 60px;
    height: 60px;
}

h1 {
    margin-left: 10px;
    font-size: 28px;
    color: #fff;
    letter-spacing: 7px;
    /* 字间距 */
    text-shadow: 5px 5px 0 #000;
}

.el-button {
    margin-left: 10px;
    margin-top: 10px;
}

.header-r {
    display: flex;
    align-items: center;
}

.header-r-img {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    margin-right: 20px;
}

span {
    margin-right: 10px;
    margin-top: 10px;
    color: #fff;
}

.el-button {
    margin-right: 50px;
}

.el-aside {
    transition: all 0.2s;
    background-image: url(../assets/images/bgc22.webp);
    background-size: cover;
    background-position: -99% 0
}

.el-menu {
    border-right: none;
}

.el-footer {
    /* background-color: #c47485; */
    background-image: url(../assets/images/bgc22.webp);
    background-position: 0 40px;
    display: flex;
    align-items: center;
}

.foot {
    color: #fff;
    font-size: 14px;
    margin: 0 auto;
    transform: translateX(-50%);
}
</style>